<?php

namespace app\webapi\controller;

use app\webapi\common\BaseController;
use app\webapi\vms\service\WebsiteService;
use app\webapi\vms\validate\WebsiteValidate;
use library\OWException;
use think\App;

/**
 * @站点控制器
 */
class WebsiteController extends BaseController
{
    /**
     * @var WebsiteValidate
     */
    protected $validate;

    /**
     * @var WebsiteService
     */
    protected $service;

    /**
     * @param App $app
     */
    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->validate = new WebsiteValidate();
        $this->service = new WebsiteService();
    }

    /**
     * @desc 获取网站token
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author zhaozhiwei
     * @time 2023/12/19-11:07
     */
    public function getToken()
    {
        $params = $this->validate->goCheck('getToken');
        $res = $this->service->getToken($params['sign']);
        return $this->responseSuccess($res);
    }

    /**
     * @desc 获取网站地址列表
     * @return \think\response\Json
     * @author zhaozhiwei
     * @time 2023/12/19-12:14
     */
    public function getWebAddressList(){
        $res = $this->service->getWebAddressList($this->website_id);
        return $this->responseSuccess($res);
    }
    /**
     * @desc 获取网站栏目树形列表
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author zhaozhiwei
     * @time 2023/12/12-14:08
     */
    public function getChannelTreeList()
    {
        $res = $this->service->getChannelTreeList($this->website_id);
        return $this->responseSuccess($res);
    }

    /**
     * @desc 获取网站基本信息
     * @return \think\response\Json
     * @author zhaozhiwei
     * @time 2023/12/12-14:09
     */
    public function getBaseInfo()
    {
        $res = $this->service->getBaseInfo($this->website_id);
        return $this->responseSuccess($res);
    }
    /**
     * @desc 设置网站基本信息
     * @return \think\response\Json
     * @author zhaozhiwei
     * @time 2023/12/12-14:37
     */
    public function setBaseInfo()
    {
        $params = $this->validate->goCheck('setBaseInfo');
        $res = $this->service->setBaseInfo($params, $this->website_id);
        return $this->responseSuccess($res);
    }

    /**
     * @desc 设置网站基础域名
     * @return \think\response\Json
     * @author zhaozhiwei
     * @time 2023/12/22-12:44
     */
    public function setBaseDomain()
    {
        $params = $this->validate->goCheck('setBaseDomain');
        $res = $this->service->setBaseDomain($params['domain_name'], $this->website_id);
        return $this->responseSuccess($res);
    }

    /**
     * @desc 修改网站状态
     * @return \think\response\Json
     * @author zhaozhiwei
     * @time 2023/12/12-14:55
     */
    public function changeStatus()
    {
        $params = $this->validate->goCheck('changeStatus');
        $res = $this->service->changeStatus($params['status'], $this->website_id);
        return $this->responseSuccess($res);
    }

    /**
     * @desc 绑定自定义域名
     * @return \think\response\Json
     * @author zhaozhiwei
     * @time 2023/12/12-15:06
     */
    public function bindCustomDomain()
    {
        $params = $this->validate->goCheck('bindCustomDomain');
        $res = $this->service->bindCustomDomain($params['domain_name'], $this->website_id);
        return $this->responseSuccess($res);
    }

    /**
     * @desc 设置备案号
     * @return \think\response\Json
     * @author zhaozhiwei
     * @time 2023/12/12-15:32
     */
    public function setRecordNumber()
    {
        $params = $this->validate->goCheck('setRecordNumber');
        $res = $this->service->setRecordNumber($params['domain_record_number'], $this->website_id);
        return $this->responseSuccess($res);
    }

    /**
     * @desc 获取域名信息
     * @return \think\response\Json
     * @author zhaozhiwei
     * @time 2023/12/12-15:32
     */
    public function getDomainInfo()
    {
        $res = $this->service->getDomainInfo($this->website_id);
        return $this->responseSuccess($res);
    }

    /**
     * @desc ssl续费
     * @return \think\response\Json
     * @author zhaozhiwei
     * @time 2023/12/12-15:58
     */
    public function sslRenew()
    {
        $res = $this->service->sslRenew($this->website_id);
        return $this->responseSuccess($res);
    }

    /**
     * @desc 域名解析验证
     * @return \think\response\Json
     * @author zhaozhiwei
     * @time 2023/12/12-16:08
     */
    public function verificationDomain()
    {
        $res = $this->service->verificationDomain($this->website_id);
        return $this->responseSuccess($res);
    }

    /**
     * @desc 栏目排序
     * @return \think\response\Json
     * @author zhaozhiwei
     * @time 2023/12/13-9:09
     */
    public function sortChannel()
    {
        $params = $this->validate->goCheck('sortChannel');
        $json_array = $this->validate->check_sort_json_array($params['json_array'], ['id' => 'number', 'sort' => 'number']);
        $res = $this->service->sortChannel($json_array, $this->website_id);
        return $this->responseSuccess($res);
    }

    /**
     * @desc 编辑栏目
     * @return \think\response\Json
     * @author zhaozhiwei
     * @time 2023/12/13-9:10
     */
    public function editChannel()
    {
        $params = $this->validate->goCheck('editChannel');
        $res = $this->service->editChannel($params, $this->website_id);
        return $this->responseSuccess($res);
    }

    /**
     * @desc 获取栏目详情信息
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author zhaozhiwei
     * @time 2023/12/13-10:02
     */
    public function getChannelInfo()
    {
        $params = $this->validate->goCheck('getChannelInfo');
        $res = $this->service->getChannelInfo($params, $this->website_id);
        return $this->responseSuccess($res);
    }

    /**
     * @desc 设置网站信息
     * @return \think\response\Json
     * @author zhaozhiwei
     * @time 2023/12/25-11:47
     */
    public function setAllInfo()
    {
        $params = $this->validate->goCheck('setAllInfo');
        $res = $this->service->setAllInfo($params, $this->website_id);
        return $this->responseSuccess($res);
    }
}